package com.ymt.order.service.impl;

import com.ymt.consumer.domain.FinancialReceipts;
import com.ymt.consumer.service.FinancialReceiptsService;
import com.ymt.enums.PayType;
import com.ymt.order.dao.OrderMapper;
import com.ymt.order.service.OrderCodeService;
import com.ymt.order.service.OrderService;
import com.ymt.producer.domain.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired(required = false)
    private FinancialReceiptsService financialReceiptsService;
    @Autowired
    private OrderCodeService orderCodeService;

    @Override
    public void payOrder(Order order) {
        order.setOrderCode(orderCodeService.createOrderCode());
        orderMapper.insert(order);

        FinancialReceipts financialReceipts = new FinancialReceipts();
        financialReceipts.setSource(PayType.getPayType(order.getPayType()).getPayKey());
        financialReceipts.setOrderCode(order.getOrderCode());
        financialReceipts.setReceipt(order.getOrderPrice());
        financialReceiptsService.recordReceipt(financialReceipts);
    }
}
